package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemCat;

import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;
    @GetMapping("findItemCatList/{level}")
    public SysResult findItemCatList(@PathVariable Integer  level){
        long startTime= System.currentTimeMillis();
        List<ItemCat> list=itemCatService.findItemCatList(level);
        long endTime = System.currentTimeMillis();
        System.out.println("执行所用时间为"+(endTime-startTime)+"毫秒");
        return SysResult.success(list);

    }

    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat);
        return SysResult.success();
    }

    @DeleteMapping("/deleteItemCat")//get 与delete是一类,接参数直接接
    public SysResult  deleteItemCat(ItemCat itemCat){
        Long startTime=System.currentTimeMillis();
        itemCatService.deleteItemCat(itemCat);
        long endTime= System.currentTimeMillis();
        System.out.println("执行所用时间为"+(endTime-startTime));
        return SysResult.success();
    };

//    @PutMapping("/status/{id}/{status}")
//    public SysResult updateStatus(@PathVariable Integer id,@PathVariable boolean status){
//        itemCatService.updateStatus(id,status);
//        return SysResult.success();
//
//    }
    @PutMapping("/status/{id}/{status}")
    public SysResult updateStatus( ItemCat itemCat){
        itemCatService.updateStatus2(itemCat);
        return SysResult.success();

    }

    @PutMapping("/updateItemCat")
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
         itemCatService.updateItemCat(itemCat);
        return SysResult.success();
    }


}
